package com.jrsoft.bim.db;

import com.jrsoft.bim.dto.*;

/**
 * ${DESCRIPTION}
 *
 * @author Blueeyedboy
 * @create 2019-12-31 5:49 PM
 **/
public class DBUtil {

	public ConnDB db;

	public DBUtil(ConnDB db){
		this.db = db;
	}

	public void insertTblStdFlr(StdFlrDTO entity){
		StringBuilder sql1 = new StringBuilder();
		sql1.append("insert into tblStdFlr(ID,No_,height)values(")
				.append(entity.getId())
				.append(",").append(entity.getNo())
				.append(",").append(entity.getHeight())
				.append(");");
		db.executeUpdateSql(sql1.toString());
	}

	public void insertTblFloor(FloorDTO entity){


		StringBuilder sql2 = new StringBuilder();
		sql2.append("insert into tblFloor(ID,No_,name,StdFlrID,LevelB,Height)values(")
				.append(entity.getId())
				.append(",").append(entity.getNo())
				.append(",").append("''")
				.append(",").append(entity.getStdFlrDTO().getId())
				.append(",").append(entity.getLevelB())
				.append(",").append(entity.getHeight())
				.append(");");
		db.executeUpdateSql(sql2.toString());
	}

	public void insertTblGrid(GridDTO entity){
		StringBuilder insertSql = new StringBuilder();
		insertSql.append("insert into tblGrid(ID,No_,StdFlrID,Jt1ID,Jt2ID,AxisID)values(")
				.append(entity.getId())
				.append(",").append(entity.getNo())
				.append(",").append(entity.getStdFlrDTO().getId())
				.append(",").append(entity.getStart().getId())
				.append(",").append(entity.getEnd().getId())
				.append(",").append(entity.getAxis().getId())
				.append(");");
		db.executeUpdateSql(insertSql.toString());
	}

	public void insertTblBeamSeg(BeamSegDTO entity){
		StringBuilder insertSql = new StringBuilder();
		insertSql.append("insert into tblBeamSeg(ID,No_,StdFlrID,SectID,GridID,Ecc,HDiff1,HDiff2,Rotation,JYDef)values(")
				.append(entity.getId())
				.append(",").append(entity.getNo())
				.append(",").append(entity.getStdFlrDTO().getId())
				.append(",").append(entity.getBeamSect())
				.append(",").append(entity.getGrid().getId())
				.append(",").append(entity.getEcc())
				.append(",").append(0)
				.append(",").append(0)
				.append(",").append(0)
				.append(",").append(0)
//				.append(",").append("'0,0,0,0,'")
				.append(");");
		db.executeUpdateSql(insertSql.toString());
	}

	public void insertTblColSeg(ColSegDTO entity){
		StringBuilder insertSql = new StringBuilder();
		insertSql.append("insert into tblColSeg(ID,No_,StdFlrID,SectID,JtID,EccX,EccY,Rotation,HDiffB,ColcapId,Cut_Col,Cut_Cap,Cut_Slab)values(")
				.append(entity.getId())
				.append(",").append(entity.getNo())
				.append(",").append(entity.getStdFlrDTO().getId())
				.append(",").append(entity.getSectID())
				.append(",").append(entity.getJointDTO().getId())
				.append(",").append(entity.getEccX())
				.append(",").append(entity.getEccY())
				.append(",").append(0)
				.append(",").append(0)
				.append(",").append(0)
				.append(",").append("''")
				.append(",").append("''")
				.append(",").append("''")
				//				.append(",").append("'0,0,0,0,'")
				.append(");");
		db.executeUpdateSql(insertSql.toString());
	}

	public void insertTblJoint(JointDTO entity){
		StringBuilder insertSql = new StringBuilder();
		insertSql.append("insert into tblJoint(ID,No_,StdFlrID,X,Y,HDIFF)values(")
				.append(entity.getId())
				.append(",").append(entity.getNo())
				.append(",").append(entity.getStdFlrDTO().getId())
				.append(",").append(entity.getX())
				.append(",").append(entity.getY())
				.append(",").append(0)
				.append(");");
		db.executeUpdateSql(insertSql.toString());
	}

	public void insertTblAxis(AxisDTO entity){
		StringBuilder insertSql = new StringBuilder();
		insertSql.append("insert into tblAxis(ID,No_,StdFlrID,Jt1ID,Jt2ID,Name)values(")
				.append(entity.getId())
				.append(",").append(entity.getNo())
				.append(",").append(entity.getStdFlrDTO().getId())
				.append(",").append(entity.getStart().getId())
				.append(",").append(entity.getEnd().getId())
				.append(",").append("''")
				.append(");");
		db.executeUpdateSql(insertSql.toString());
	}
}
